# 数据（100轮训练）
np.random.seed(42)
epochs = np.arange(1, 101)
entropy = 1.2 * np.exp(-0.03 * epochs) + 0.1 * np.random.randn(100)
accuracy = 85 * (1 - np.exp(-0.05 * epochs)) + 0.2 * np.random.randn(100)

fig, ax1 = plt.subplots(figsize=(5,3))
ax1.plot(epochs, entropy, 'b-', linewidth=2, label=r'State Entropy $\mathcal{E}_k^{(t)}$')
ax1.set_xlabel('Training Rounds', fontsize=12)
ax1.set_ylabel(r'Entropy $\mathcal{E}_k^{(t)}$', color='b', fontsize=12)
ax1.tick_params(axis='y', labelcolor='b')
ax1.set_ylim(0, 1.5)

ax2 = ax1.twinx()
ax2.plot(epochs, accuracy, 'r--', linewidth=2, label='Test Accuracy')
ax2.set_ylabel('Accuracy (%)', color='r', fontsize=12)
ax2.tick_params(axis='y', labelcolor='r')
ax2.set_ylim(0, 90)

# 标注三阶段
ax1.axvline(x=30, color='gray', linestyle=':', alpha=0.7)
ax1.axvline(x=70, color='gray', linestyle=':', alpha=0.7)
ax1.text(15, 1.3, "Exploration Phase\n(High Entropy)", fontsize=10, ha='center')
ax1.text(50, 1.3, "Transition Phase", fontsize=10, ha='center')
ax1.text(85, 1.3, "Convergence Phase\n(Low Entropy)", fontsize=10, ha='center')

# 修正斜率计算（基于式(7)熵变率定义）
delta_H = entropy[0] - entropy[30]  # 前30轮总衰减量
slope_per_10rounds = delta_H / 3    # 每10轮平均衰减量
# ax1.annotate(f'Slope: {slope_per_10rounds:.2f}/10 rounds', 
#              xy=(15, 0.8), xytext=(15, 0.5), 
#              arrowprops=dict(arrowstyle='->'), fontsize=10)

# plt.title('Co-evolution of Entropy and Accuracy', fontsize=14)
fig.legend( bbox_to_anchor=(0.9, 0.85))
plt.savefig('entropy_accuracy_evolution_en.png', bbox_inches='tight')
